package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.pojo.entity.Material;
import com.example.pojo.entity.Warehouse;
import com.example.service.IWarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @author wy
 * @since 2024/7/25
 */
@RestController
@RequestMapping("/warehouse")
@Api(tags = "仓库接口")
@Slf4j
public class WarehouseController {

    @Autowired
    private IWarehouseService iWarehouseService;

    /**
     * 分页查询
     */
    @ApiOperation("分页展示仓库信息列表")
    @GetMapping("/selectPage")
    public Result selectPage(Warehouse warehouse,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<Warehouse> page = iWarehouseService.selectPage(warehouse, pageNum, pageSize);
        return Result.success(page);
    }

    @PostMapping("/add")
    @ApiOperation("新增仓库信息")
    public Result add(@RequestBody Warehouse warehouse) {
        iWarehouseService.add(warehouse);
        return Result.success(warehouse);
    }

    @PutMapping("/update")
    @ApiOperation("修改仓库信息")
    public Result update(@RequestBody Warehouse warehouse){
        iWarehouseService.updateById(warehouse);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("通过仓库id删除仓库信息")
    public Result delete(@PathVariable("id") Integer id){
        iWarehouseService.delete(id);
        return Result.success();
    }
}
